<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" size="small" :inline="true" label-width="90px">
      <el-form-item label="客户姓名：" prop="clientName">
        <el-input v-model="queryParams.clientName" placeholder="客户姓名" clearable style="width: 300px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="手机号码：" prop="clientPhone">
        <el-input v-model="queryParams.phone" placeholder="客户手机号码" clearable style="width: 300px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="身份证号：" prop="citizenIdentity">
        <el-input v-model="queryParams.citizenIdentity" placeholder="客户身份证号" clearable style="width: 300px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="渠道名称：" prop="channel">
        <el-select v-model="queryParams.channelName" placeholder="全部" clearable style="width: 300px"
          @visible-change="selectChannelName($event)">
          <el-option v-for="item in channelNameOPtions" :key="item.id" :label="item.name" :value="item">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="申请状态：" prop="applicantStatus">
        <el-select v-model="queryParams.applicantStatus" placeholder="全部" clearable style="width: 300px"
          @visible-change="selectApplicantStatus($event)">
          <el-option v-for="item in applicantStatusOptions" :key="item.id" :label="item.name" :value="item">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="来源" prop="origin">
        <!-- <el-select v-model="queryParams.origin" placeholder="订单来源" clearable style="width: 240px"
        @visible-change="selectOrigin($event)">
          <el-option v-for="item in originOptions" :key="item.id" :label="item.name" :value="item">
          </el-option>
        </el-select> -->
        <el-select v-model="value" placeholder="订单来源">
          <el-option v-for="item in originOptions" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="申请时间：">
        <el-date-picker v-model="dateRange" style="width: 300px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" />
      </el-form-item>
      <el-form-item>
        <div style="margin-right: 50px;">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </div>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermi="['system:post:add']" type="primary" plain icon="el-icon-plus" size="mini" @click="jump">
          新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermi="['system:post:export']" type="warning" plain icon="el-icon-download" size="mini"
          @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>
    <!-- data=你后台查出的数据 -->
    <el-table v-loading="loading" :data="feedList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="40" align="center" />
      <el-table-column label="产品名称" align="center" prop="productionName" />
      <el-table-column label="客户姓名" align="center" prop="clientName" />
      <el-table-column label="申请金额" align="center" prop="loanAmount" />
      <el-table-column label="期数" align="center" prop="periods" />
      <el-table-column label="渠道" align="center" prop="channelName" />
      <el-table-column label="申请时间" align="center" prop="appliedTime" width="180" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.appliedTime)}}</span>
        </template>
      </el-table-column>
     
      <el-table-column label="申请次数" align="center" prop="appliedNumber" />
      <el-table-column label="申请状态" align="center" prop="applicantStatus" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-hasPermi="['system:post:edit']" size="mini" type="text" icon="el-icon-more"
            @click="handleDetail(scope.row)">查看</el-button>
          <el-button v-if="scope.row.appliedStatus <=3" v-hasPermi="['system:post:remove']" size="mini" type="text"
            icon="el-icon-edit" @click="handleUpdate(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
// 导入api
import { listCustomFeed, findApplicantStatus, findOrigin, findChannel } from '@/api/applicat'


export default {
  // 字典导入
  dicts: ['order_status', 'source_status'],
  data() {
    return {
      clientId: undefined,
      applicantStatusOptions: [],
      originOptions: [],
      channelNameOPtions: [],
      originOptions: [{
        value: '选项1',
        label: 'PC'
      }, {
        value: '选项2',
        label: 'iOS'
      }, {
        value: '选项3',
        label: 'iPad'
      }, {
        value: '选项4',
        label: 'Android'
      }
      ],
      value: '',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      feedList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        clientNmae: undefined,
        phone: undefined,
        citizenIdentity: undefined,
        phone: undefined,
        channelName: undefined,
        applicantStatus: undefined,
        origin: undefined

      },
      // 表单参数
      form: {},
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      console.log(this.addDateRange(this.queryParams, this.dateRange))
      listCustomFeed(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        console.log(response.rows)
        this.feedList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    selectApplicantStatus(handle) {
      findApplicantStatus().then(
        res => {
          this.applicantStatusOptions = res.data
        }
      ).catch()
    },
    selectChannelName() {
      findChannel().then(
        res => {
          console.log(res)
          this.channelNameOPtions = res.data

        }
      ).catch(err => {
        console.log(err)
      })
    },
    selectOrigin(handle) {
      findOrigin().then(
        res => {
          this.originOptions = res.data
        }
      ).catch()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleQuery() {
      console.log('这是点击事件')
      this.getList()
    },
    // 查看进件详情
    handleDetail(row) {
      const feedId = row.id;
      const clientId = row.clientId
      this.$router.push({
        path: "/customFeed/viewDetails/",
        query: {
          handle: 'viewDetails',
          feedId: feedId,
          clientId: clientId
        }
      });

    },

    reset() {
      this.form = {
        code: 1,
        status: '0'
      }
      this.resetForm('form')
    },
    jump() {
      this.$router.push(
        {
          path: '/customFeed/addNewFeed/step1',
          query: {
            handle: 'add1'
          }
        }
      )
    },
    handleExport() {
      this.download('http://localhost:8080/feed/export', {
        ...this.queryParams
      }, `post_${new Date().getTime()}.xlsx`)
    },
    handleUpdate(row) {
      const feedId = row.id;
      this.$router.push({
        path: "/customFeed/updateFeed/",
        query: {
          handle: 'update',
          feedId: feedId,
          clientId: row.clientId
        }
      });
    },

    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.postId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    }
  },


}

</script>

